<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Base\Annotation\Common;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ApiResource()
 * @ODM\Document(repositoryClass="App\Repository\OrdersRepository")
 */
class Orders
{
    /**
     * @Common(cnName="#",editType="text",listType="text")
     * @ODM\Id(strategy="INCREMENT")
     * @Groups({"order"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Common(cnName="订单号",editType="text",listType="text")
     * @ODM\Field( nullable=true)
     * @Groups({"order"})
     * @ORM\Column(type="string", length=255)
     */
    private $sn;

    /**
     * @Common(cnName="下单时间",editType="text",listType="text")
     * @ODM\Field( type="date", nullable=true)
     * @Groups({"order"})
     * @ORM\Column(type="datetime")
     */
    private $createAt;

    /**
     * @Common(cnName="总金额",editType="text",listType="text")
     * @ODM\Field(type="raw")
     * @Groups({"order"})
     * @ORM\Column(type="float")
     */
    private $payTotal;

    /**
     * @Common(cnName="实付金额",editType="text",listType="text")
     * @ODM\Field(type="raw")
     * @Groups({"order"})
     * @ORM\Column(type="float")
     */
    private $payReal;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field( type="date", nullable=true)
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $payAt;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @ORM\Column(type="smallint")
     * @Groups({"order"})
     */
    private $payType;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @ORM\Column(type="string", length=255)
     */
    private $paCode;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field(type="raw")
     * @ORM\Column(type="json", nullable=true)
     * @Groups({"order"})
     */
    private $sales = [];

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field( type="date", nullable=true)
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $settleAt;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field(type="date")
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $settleMessage;

    /**
     * @Common(cnName="名称",editType="text",listType="text")
     * @ODM\Field(type="raw")
     * @Groups({"order"})
     * @ORM\Column(type="smallint")
     */
    private $status;

    /**
     * @Groups({"order"})
     * @ODM\ReferenceMany(targetDocument="App\Entity\OrderPackage", mappedBy="orders", orphanRemoval=true)
     * @ORM\OneToMany(targetEntity="App\Entity\OrderPackage", mappedBy="orders", orphanRemoval=true)
     */
    private $package;

    /**
     * @Common(cnName="明细",editType="text",listType="text")
     * @ODM\Field(type="raw")
     * @ORM\Column(type="json", nullable=true)
     * @Groups({"order"})
     */
    private $info = [];

    /**
     * @Common(cnName="用户",editType="text",listType="text")
     * @Groups({"order"})
     * @ODM\ReferenceOne(targetDocument="App\Entity\User")
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
     */
    private $user;


    /**
     * @Common(cnName="核销状态",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @Groups({"order"})
     * @ORM\Column(type="smallint")
     */
    private $checkStatus;


    /**
     * @Common(cnName="核销工作人员",editType="text",listType="text")
     * @ODM\Field(type="raw", nullable=true)
     * @Groups({"order"})
     * @ORM\Column(type="smallint")
     */
    private $checkUser;

    /**
     * @Common(cnName="核销时间",editType="text",listType="text")
     * @ODM\Field( type="date", nullable=true)
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $checkAt;



    public function __construct()
    {
        $this->package = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getSn(): ?string
    {
        return $this->sn;
    }

    public function setSn(string $sn): self
    {
        $this->sn = $sn;

        return $this;
    }

    public function getCreateAt(): ?\DateTimeInterface
    {
        return $this->createAt;
    }

    public function setCreateAt(\DateTimeInterface $createAt): self
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getPayTotal(): ?float
    {
        return $this->payTotal;
    }

    public function setPayTotal(float $payTotal): self
    {
        $this->payTotal = $payTotal;

        return $this;
    }

    public function getPayReal(): ?float
    {
        return $this->payReal;
    }

    public function setPayReal(float $payReal): self
    {
        $this->payReal = $payReal;

        return $this;
    }

    public function getPayAt(): ?\DateTimeInterface
    {
        return $this->payAt;
    }

    public function setPayAt(?\DateTimeInterface $payAt): self
    {
        $this->payAt = $payAt;

        return $this;
    }

    public function getPayType(): ?int
    {
        return $this->payType;
    }

    public function setPayType(int $payType): self
    {
        $this->payType = $payType;

        return $this;
    }

    public function getPaCode()
    {
        return $this->paCode;
    }

    public function setPaCode( $paCode): self
    {
        $this->paCode = $paCode;

        return $this;
    }

    public function getSales(): ?array
    {
        return $this->sales;
    }

    public function setSales(?array $sales): self
    {
        $this->sales = $sales;

        return $this;
    }

    public function getSettleAt(): ?\DateTimeInterface
    {
        return $this->settleAt;
    }

    public function setSettleAt(?\DateTimeInterface $settleAt): self
    {
        $this->settleAt = $settleAt;

        return $this;
    }

    public function getSettleMessage(): ?string
    {
        return $this->settleMessage;
    }

    public function setSettleMessage(?string $settleMessage): self
    {
        $this->settleMessage = $settleMessage;

        return $this;
    }

    public function getStatus(): ?int
    {
        return $this->status;
    }

    public function setStatus(int $status): self
    {
        $this->status = $status;

        return $this;
    }

    /**
     * @return Collection|OrderPackage[]
     */
    public function getPackage(): Collection
    {
        return $this->package;
    }

    public function addPackage(OrderPackage $package): self
    {
        if (!$this->package->contains($package)) {
            $this->package[] = $package;
            $package->setOrders($this);
        }

        return $this;
    }

    public function removePackage(OrderPackage $package): self
    {
        if ($this->package->contains($package)) {
            $this->package->removeElement($package);
            // set the owning side to null (unless already changed)
            if ($package->getOrders() === $this) {
                $package->setOrders(null);
            }
        }

        return $this;
    }

    public function getInfo(): ?array
    {
        return $this->info;
    }

    public function setInfo(?array $info): self
    {
        $this->info = $info;

        return $this;
    }

    public function getUser(): ?User
    {
        return $this->user;
    }

    public function setUser(?User $user): self
    {
        $this->user = $user;

        return $this;
    }

    public function getCheckStatus(): ?int
    {
        return $this->checkStatus;
    }

    public function setCheckStatus(int $checkStatus): self
    {
        $this->checkStatus = $checkStatus;

        return $this;
    }

    public function getCheckUser(): ?int
    {
        return $this->checkUser;
    }

    public function setCheckUser(int $checkUser): self
    {
        $this->checkUser = $checkUser;

        return $this;
    }

    public function getCheckAt(): ?\DateTimeInterface
    {
        return $this->checkAt;
    }

    public function setCheckAt(?\DateTimeInterface $checkAt): self
    {
        $this->checkAt = $checkAt;

        return $this;
    }
}
